﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;


    class docxFile : ExtractFile
    {
        public docxFile(FileInfo f)
            : base(f)
        {            
            Microsoft.Office.Interop.Word.ApplicationClass wordApp = null;
            object nullobj = System.Reflection.Missing.Value;

            try
            {
                wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                object file = f.FullName;
                Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
                                                                                    ref nullobj, ref nullobj, ref nullobj,
                                                                                    ref nullobj, ref nullobj, ref nullobj,
                                                                                    ref nullobj, ref nullobj, ref nullobj,
                                                                                    ref nullobj, ref nullobj, ref nullobj, ref nullobj);
                doc.ActiveWindow.Selection.WholeStory();
                allText = doc.Content.Text;//.ActiveWindow.Selection.Copy();
                //IDataObject data = Clipboard.GetDataObject();

                ////get all Text
                //allText = data.GetData(DataFormats.UnicodeText).ToString().Trim();
            }
            catch { }
            finally
            {
                if (wordApp != null)
                {
                    //doc.Close(ref nullobj, ref nullobj, ref nullobj);
                    wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
                }
            }
        }
    }
